package restful;

public class Brackets {

	private final int count;

	public Brackets(String pattern) {

		final int open = count(pattern, '{');
		final int close = count(pattern, '}');

		if (open != close) throw new RuntimeException("open { must match with close }");

		count = open;
	}

	private int count(String pattern, char c) {
		int count = 0;
		for (int i = 0; i < pattern.length(); i++) {
			if (pattern.charAt(i) == c) {
				count++;
			}
		}
		return count;
	}

	public int getCount() {
		return count;
	}

}
